package com.mobile.challenge.web;
import com.mobile.challenge.core.Result;
import com.mobile.challenge.core.ResultGenerator;
import com.mobile.challenge.model.User;
import com.mobile.challenge.service.UserService;
import com.mobile.challenge.util.DES;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
* Created by Lix on 2018/06/04.
*/
@RestController
@Api(value = "访问接口",tags = {"访问记录管理"})
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 是否访问过(带锁)
     * @param user
     * @return
     */
    @RequestMapping(value = "/ifOldHand", method = RequestMethod.POST, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "是否访问过", notes = "必须提供一个phoneNo")
    public synchronized Result getRemCount4Challenge(@RequestBody User user) {
        //是否访问过
        Map data = userService.findByPhoneNo(user.getPhoneNo());
        data.put("phoneNo",user.getPhoneNo());
        return ResultGenerator.genSuccessResult(data);
    }

//    /**
//     * 访问(带锁)
//     * @param user
//     * @return
//     */
//    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = {"application/json"})
//    @ResponseStatus(HttpStatus.OK)
//    @ApiOperation(value = "访问", notes = "必须提供一个phoneNo,进入活动初始化页面时请求此接口")
//    public synchronized Result add(@RequestBody User user) {
//        Map data = new HashMap();
//        //访问
//        Map rs = userService.takePartIn(user);
//        if(!(boolean)rs.get("code")){
//            return ResultGenerator.genFailResult((String) rs.get("msg"),data);
//        }
//        return ResultGenerator.genSuccessResult(data);
//    }

}
